/*
 * @lc app=leetcode.cn id=14 lang=typescript
 *
 * [14] 最长公共前缀
 */

// @lc code=start
function longestCommonPrefix(strs: string[]): string {
    let cursor = 0;
    const biggest = Math.min(...strs.map((i) => i.length));
    let col = "";
    while (cursor < biggest) {
        let now!: string;
        for (let i of strs) {
            if (now === undefined) {
                now = i[cursor];
                continue;
            }
            if (i[cursor] === now) {
                continue;
            } else {
                return col;
            }
        }
        col += now;
        cursor++;
    }
    return col;
}
// @lc code=end
